//
//  LJJSingleTableViewCell.m
//  shopTest
//
//  Created by 梁佳佳 on 2016/11/17.
//  Copyright © 2016年 梁佳佳. All rights reserved.
//

#import "LJJSingleTableViewCell.h"

@interface LJJSingleTableViewCell ()

@end

@implementation LJJSingleTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addSubview:self.iconImageView];
        [self addSubview:self.countryImageView];
        [self addSubview:self.titleLabel];
        [self addSubview:self.contentLabel];
        [self addSubview:self.priceLabel];
        [self addSubview:self.buyCarButton];
    }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    __weak typeof(self) weakSelf = self;
    [_iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(140, 140));
        make.centerY.equalTo(weakSelf.mas_centerY);
        make.left.equalTo(weakSelf.mas_left).offset(5);
    }];
    
    [_countryImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(25, 20));
        make.left.equalTo(weakSelf.iconImageView.mas_left).offset(8);
        make.top.equalTo(weakSelf.iconImageView.mas_top).offset(8);
    }];
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(weakSelf.mas_right).offset(-15);
        make.left.equalTo(weakSelf.iconImageView.mas_right).offset(6);
        make.top.equalTo(weakSelf.mas_top).offset(25);
        make.height.equalTo(@15);
    }];
    
    [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.titleLabel.mas_bottom).offset(7);
        make.right.equalTo(weakSelf.mas_right).offset(-15);
        make.left.equalTo(weakSelf.iconImageView.mas_right).offset(6);
        make.height.equalTo(@60);
    }];
    
    [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@15);
        make.left.equalTo(weakSelf.iconImageView.mas_right).offset(6);
        make.right.equalTo(weakSelf.buyCarButton.mas_left).offset(-20);
        make.bottom.equalTo(weakSelf.mas_bottom).offset(-23);
    }];
    
    [_buyCarButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(37, 37));
        make.right.equalTo(weakSelf.mas_right).offset(-20);
        make.bottom.equalTo(weakSelf.mas_bottom).offset(-20);
    }];
}
- (void)setModel:(LJJSingleRootModel *)model
{
    _model = model;
    [_iconImageView sd_setImageWithURL:[NSURL URLWithString:model.ImgView]];
    [_countryImageView sd_setImageWithURL:[NSURL URLWithString:model.CountryImg]];
    _titleLabel.text = model.Title;
    _contentLabel.text = model.GoodsIntro;
    [self priceAttributedString];
}
- (void)priceAttributedString{
    //当前价格(需要手动添加人民币符号)
    NSString *nowPrice = [NSString stringWithFormat:@"¥%@ ",_model.DomesticPrice];
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc]initWithString:nowPrice attributes:@{NSForegroundColorAttributeName:RGB(230, 51, 37, 1),NSFontAttributeName:[UIFont boldSystemFontOfSize:16.0]}];
    //过去价格
    NSString *oldString = [NSString stringWithFormat:@"%@ ",_model.Price];
    NSMutableAttributedString *oldPrice = [[NSMutableAttributedString alloc]initWithString:oldString attributes:@{NSForegroundColorAttributeName:RGB(132, 132, 132, 1),NSFontAttributeName:[UIFont systemFontOfSize:11.0],NSStrikethroughStyleAttributeName:@(2)}];
    [string insertAttributedString:oldPrice atIndex:string.length];
    _priceLabel.attributedText = string;
}
#pragma mark -
#pragma mark - lazy method
- (UIImageView *)iconImageView
{
    if (!_iconImageView) {
        _iconImageView = [[UIImageView alloc] init];
    }
    return _iconImageView;
}
- (UIImageView *)countryImageView
{
    if (!_countryImageView) {
        _countryImageView = [[UIImageView alloc] init];
    }
    return _countryImageView;
}
- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = [UIFont boldSystemFontOfSize:14.0];
        _titleLabel.textColor = RGB(81, 81, 81, 1);
    }
    return _titleLabel;
}
- (UILabel *)contentLabel
{
    if (!_contentLabel) {
        _contentLabel = [[UILabel alloc] init];
        _contentLabel.font = [UIFont systemFontOfSize:13.0];
        _contentLabel.textColor = RGB(35, 35, 35, 1);
        _contentLabel.numberOfLines = 3;
    }
    return _contentLabel;
}
- (UILabel *)priceLabel
{
    if (!_priceLabel) {
        _priceLabel = [[UILabel alloc] init];
    }
    return _priceLabel;
}
- (UIButton *)buyCarButton
{
    if (!_buyCarButton) {
        _buyCarButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_buyCarButton setImage:[UIImage imageNamed:@"限时特卖界面购物车图标"] forState:UIControlStateNormal];
    }
    return _buyCarButton;
}
- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

@end
